package com.ch.light.web.controller;

import com.ch.light.core.Response;
import com.ch.light.core.page.Page;
import com.ch.light.mybatis.ParamFilter;
import com.ch.light.web.aop.annotaion.WebLogger;
import com.ch.light.web.model.LoginLog;
import com.ch.light.web.service.LoginLogService;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import javax.annotation.Resource;


@Controller
@RequestMapping("loginLog")
public class LoginLogController {

    @Autowired
    private LoginLogService loginLogService;

    @GetMapping("listPage")
    public String list() {
        return "loginLogList";
    }

    @ResponseBody
    @PostMapping("list")
    @WebLogger("查询登录日志列表")
    public Response list(@RequestBody ParamFilter queryFilter) {
        List<LoginLog> records = loginLogService.getList(queryFilter);
        PageInfo<LoginLog> pageInfo = new PageInfo<>(records);
        Page page = queryFilter.getPage();
        page.setResultCount(Long.valueOf(pageInfo.getTotal()).intValue());
        return new Response(records, page);
    }
}
